package com.arturjaneczko.services.impl.state;

import java.util.List;

import com.arturjaneczko.components.core.IClipboard;
import com.arturjaneczko.components.impl.Clipboard;
import com.arturjaneczko.components.impl.ClipboardObject;
import com.arturjaneczko.services.core.state.IClipboardMode;

public abstract class DefaultClipboardMode implements IClipboardMode {

	protected IClipboard clipboard;
	protected OperatingClipboardMode operatingClipboardMode;

	public DefaultClipboardMode(OperatingClipboardMode operatingClipboardMode) {
		this.operatingClipboardMode = operatingClipboardMode;
		clipboard = new Clipboard();
	}

	@Override
	public void clear(List<ClipboardObject> clipboardList) {
		clipboard.clear();
		clipboardList.clear();
	}

	@Override
	public void clearAll(
			@SuppressWarnings("unchecked") List<ClipboardObject>... clipboardList) {
		clipboard.clearAll();
		organizeClearAll(clipboardList);
	}

	@Override
	public void copy(
			ClipboardObject clipboardObject,
			@SuppressWarnings("unchecked") List<ClipboardObject>... clipboardList) {
		clipboard.copy(clipboardList);
		organizeCopy(clipboardObject, clipboardList);
	}

	private void organizeClearAll(
			@SuppressWarnings("unchecked") List<ClipboardObject>... clipboardList) {
		for (int i = 0; i < clipboardList.length; i++)
			clipboardList[i].clear();
	}

	private void organizeCopy(
			ClipboardObject clipboardObject,
			@SuppressWarnings("unchecked") List<ClipboardObject>... clipboardList) {
		for (int i = 0; i < clipboardList.length; i++)
			clipboardList[i].add(clipboardObject);
	}

	@Override
	public abstract List<ClipboardObject> paste(
			ClipboardObject clipboardObject);

}
